package com.cloudsigns.factorymanager2.produce.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartFeedbackResponse;

import java.util.ArrayList;
import java.util.List;

public class ProduceFeedbackAdapter extends BaseAdapter {
    private Context context;
    private List<WorkPartFeedbackResponse> workPartFeedbackResponseList = new ArrayList<>();

    public ProduceFeedbackAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<WorkPartFeedbackResponse> list) {
        this.workPartFeedbackResponseList.clear();
        if (null != list) {
            this.workPartFeedbackResponseList.addAll(list);
        }
    }

    @Override
    public int getCount() {
        return workPartFeedbackResponseList.size();
    }

    @Override
    public WorkPartFeedbackResponse getItem(int position) {
        return workPartFeedbackResponseList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (null == view) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_produce_feedback, null);
            holder.tv_feedback_type = view.findViewById(R.id.tv_feedback_type);
            holder.tv_workpart_name = view.findViewById(R.id.tv_workpart_name);
            holder.tv_feedback_status=view.findViewById(R.id.tv_feedback_status);
            holder.v_1=view.findViewById(R.id.v_1);
            holder.rl_unusual_reply=view.findViewById(R.id.rl_unusual_reply);
            holder.tv_unusual_reply_status=view.findViewById(R.id.tv_unusual_reply_status);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        WorkPartFeedbackResponse workPartFeedbackResponse = workPartFeedbackResponseList.get(position);
        CommonEnum.WorkPartType type = workPartFeedbackResponse.getType();
        if (null != type) {
            if (type == CommonEnum.WorkPartType.NORMAL) {
                holder.tv_feedback_type.setText(context.getResources().getString(R.string.normal_feedback));

            } else if (type == CommonEnum.WorkPartType.UNUSUAL) {
                holder.tv_feedback_type.setText(context.getResources().getString(R.string.unusual_feedback));

//                CommonEnum.WorkPartSubType subType = workPartFeedbackResponse.getSubType();
//                if (null != subType) {
//                    if (subType == CommonEnum.WorkPartSubType.PLAN_UNUSUAL){
//                        holder.tv_feedback_type.setText(context.getResources().getString(R.string.plan_unusual));
//                    } else if (subType == CommonEnum.WorkPartSubType.PRODUCE_UNUSUAL) {
//                        holder.tv_feedback_type.setText(context.getResources().getString(R.string.machin_unusual));
//                    }
//                }

            } else if (type == CommonEnum.WorkPartType.APPLY_ADJUST) {
                holder.tv_feedback_type.setText(context.getResources().getString(R.string.application_adjustment));

            } else if (type == CommonEnum.WorkPartType.APPLY_RETURN) {
                holder.tv_feedback_type.setText(context.getResources().getString(R.string.application_rework));

            } else if (type == CommonEnum.WorkPartType.APPLY_SCRAP) {
                holder.tv_feedback_type.setText(context.getResources().getString(R.string.application_scrap));
            }
        }
        holder.tv_workpart_name.setText(" / " + workPartFeedbackResponse.getWorkPartName());

        CommonEnum.FeedbackStatus status = workPartFeedbackResponse.getStatus();
        if (null != status) {
            if (status == CommonEnum.FeedbackStatus.WAIT_CONFIRM) {
                holder.tv_feedback_status.setText(context.getResources().getString(R.string.wait_confirmed));
                holder.tv_feedback_status.setTextColor(context.getResources().getColor(R.color.rgb_FFC000));
                holder.v_1.setVisibility(View.GONE);
                holder.rl_unusual_reply.setVisibility(View.GONE);

            }else if (status == CommonEnum.FeedbackStatus.CONFIRM_FINISH) {
                holder.tv_feedback_status.setText(context.getResources().getString(R.string.already_confirmed));
                holder.tv_feedback_status.setTextColor(context.getResources().getColor(R.color.color_2c9a2d));
                holder.v_1.setVisibility(View.GONE);
                holder.rl_unusual_reply.setVisibility(View.GONE);

            }else if (status == CommonEnum.FeedbackStatus.WAIT_REPLY_CONFIRM) {
                holder.tv_feedback_status.setText(context.getResources().getString(R.string.already_confirmed));
                holder.tv_feedback_status.setTextColor(context.getResources().getColor(R.color.color_2c9a2d));
                holder.v_1.setVisibility(View.VISIBLE);
                holder.rl_unusual_reply.setVisibility(View.VISIBLE);

            }else if (status == CommonEnum.FeedbackStatus.REPLY_CONFIRM_FINISH) {
                holder.tv_feedback_status.setText(context.getResources().getString(R.string.already_confirmed));
                holder.tv_feedback_status.setTextColor(context.getResources().getColor(R.color.color_2c9a2d));
                holder.v_1.setVisibility(View.GONE);
                holder.rl_unusual_reply.setVisibility(View.GONE);

            }
        }

        return view;
    }

    static class ViewHolder {
        TextView tv_feedback_type;
        TextView tv_workpart_name;
        TextView tv_feedback_status;
        View v_1;
        RelativeLayout rl_unusual_reply;
        TextView tv_unusual_reply_status;
    }
}
